using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Collections;

namespace CocaCola_Inventory_System
{
    public partial class Form1 : Form
    {
        OdbcConnection con;
       
        DataSet ds;
        OdbcDataAdapter adp;
        ArrayList names;
        ArrayList value;
        ArrayList types;
        ArrayList users;
        ArrayList depresionation;
        ArrayList AD;
        Insert ins;
        DataTable tb;
        DataTable conditions;
        DataTable depressiation;
        DataTable category;
        DataTable type;
        ArrayList details;
        DataTable user;
        DataTable detail;
        DataTable BU;
        DataTable Countries;
        DataTable Locations;
        DB data;
        int textbox;
        TextBox[] array;
        public Form1()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please Insert Item Name");
                return;
            }
            if (textBox18.Text == "")
            {
                MessageBox.Show("Please Insert Serial Number");
                return;
            }
            decimal acq;
            try
            {
                acq = Convert.ToDecimal(textBox2.Text);

            }
            catch
            {
                MessageBox.Show("Error, Please Enter a Number for the Acq. Value");
                return;
            }
            if (comboBox1.SelectedIndex < 0 || comboBox1.SelectedIndex >= comboBox1.Items.Count)
                return;
            if (comboBox2.SelectedIndex < 0 || comboBox2.SelectedIndex >= comboBox2.Items.Count)
                return;
            //if (comboBox5.SelectedIndex < 0 || comboBox5.SelectedIndex >= comboBox5.Items.Count)
              //  return;
            
            if (comboBox5.SelectedIndex < 0 || comboBox5.SelectedIndex >= comboBox5.Items.Count)
                  return;
              if (comboBox10.SelectedIndex < 0 || comboBox10.SelectedIndex >= comboBox10.Items.Count)
                  return;
              if (comboBox6.SelectedIndex < 0 || comboBox6.SelectedIndex >= comboBox6.Items.Count)
                  return;
              if (comboBox7.SelectedIndex < 0 || comboBox7.SelectedIndex >= comboBox7.Items.Count)
                  return;
          //if (comboBox3.SelectedIndex < 0 || comboBox3.SelectedIndex >= AD.Count)
                //return;
            //Convert.ToInt32(AD[comboBox3.SelectedIndex]);

              if (!ins.item(textBox22.Text, conditions.Rows[comboBox5.SelectedIndex][1].ToString(), textBox21.Text, textBox18.Text, textBox1.Text, Convert.ToDecimal(textBox2.Text), 0, 0, dateTimePicker1.Value, Convert.ToInt32(comboBox6.SelectedValue), dateTimePicker2.Value, Convert.ToInt32(comboBox1.SelectedValue), Convert.ToInt32(comboBox2.SelectedValue), 5, Convert.ToInt32(comboBox7.SelectedValue), names.ToArray(), value.ToArray(), ((CocaCola_Inventory_System.Forms.Container)this.MdiParent).id, dateTimePicker3.Value, dateTimePicker4.Value, checkBox1.Checked, Convert.ToInt32(Locations.Rows[comboBox10.SelectedIndex][0])))
                  MessageBox.Show("Item Failed To Insert");
              else
              {
                  MessageBox.Show("Item Inserted Successfuly");
                  textBox1.Text = "";
                  textBox18.Text = "";
                  textBox21.Text = "";
                  textBox2.Text = "";
                  textBox20.Text = "";
                  textBox22.Text = "";
                  textBox8.Text = "";
              }

           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (((CocaCola_Inventory_System.Forms.Container)this.MdiParent).security < 2)
            {
                MessageBox.Show("Not Authorized");
                return;
            }
            con = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=10.87.212.173;Port=3306;Database=inventorydb;User=root; Password=kym07;Option=3;");
            names = new ArrayList();
            value = new ArrayList();
            array = new TextBox[20];
            /*
            array[5] = textBox5;
            array[7] = textBox7;
            array[13] = textBox13;
            array[14] = textBox14;
            array[16] = textBox16;
            array[15] = textBox15;
            array[17] = textBox17;
            array[19] = textBox19;*/
            ins = new Insert(((CocaCola_Inventory_System.Forms.Container)this.MdiParent).con);
            data = new DB();
            //comboBox1.Items.Add("kamal");
           // comboBox2.Items.Add("kamal");
            //comboBox3.Items.Add("kamal");
            retrieve r = new retrieve(((CocaCola_Inventory_System.Forms.Container)this.MdiParent).con);
            //r.fillDataset(data);
            retreive();
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox8.Text == "")
                return;
            if (comboBox4.SelectedIndex < 0 || comboBox4.SelectedIndex >= comboBox4.Items.Count)
                return;
            //names.Add(details[comboBox4.SelectedIndex]);
            names.Add(detail.Rows[comboBox4.SelectedIndex][0]);
           // names.Add(comboBox4.SelectedValue.ToString());

            value.Add(textBox8.Text);
            
            //listBox1.Items.Add(comboBox4.SelectedItem.ToString() + ":" + textBox8.Text);
           
            listBox1.Items.Add(detail.Rows[comboBox4.SelectedIndex][1] + ":" + textBox8.Text);
           
           
        }
        

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0 || listBox1.SelectedIndex >= names.Count)
                return;
            int i = listBox1.SelectedIndex;
            //comboBox4.Items.Add(names[i]);
            names.RemoveAt(i);
            value.RemoveAt(i);

            listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            listBox1.Update();

        }

        private void retreive()
        {
            if(!backgroundWorker1.IsBusy)
            backgroundWorker1.RunWorkerAsync();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            if (con.State != ConnectionState.Open)
                con.Open();
            
            if (((CocaCola_Inventory_System.Forms.Container)this.MdiParent).security < 2)
            {
                MessageBox.Show("Not Authorized");
                return;
            }
            if (textBox9.Text == "")
            {
                MessageBox.Show("Please Insert Name");
                return;
            }
            if (ins.type(textBox9.Text, textBox10.Text, ((CocaCola_Inventory_System.Forms.Container)this.MdiParent).id))
               MessageBox.Show("Type Inserted Successfuly"); 
           else
               MessageBox.Show("Type Failed To Insert");

           textBox10.Text = "";
           textBox9.Text = "";
           //if (con.State != ConnectionState.Closed)
              // con.Close();
           
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (((CocaCola_Inventory_System.Forms.Container)this.MdiParent).security < 2)
            {
                MessageBox.Show("Not Authorized");
                return;
            }
            if (textBox12.Text == "")
            {
                MessageBox.Show("Please Insert Name");
                return;
            }
            if (ins.detail_type(textBox12.Text, textBox11.Text, ((CocaCola_Inventory_System.Forms.Container)this.MdiParent).id))
                MessageBox.Show("Detail Type Inserted Successfuly");
            else
                MessageBox.Show("Detail Type Failed To Insert");

            textBox11.Text = "";
            textBox12.Text = "";
            
        }

        private void retrieveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            retreive();
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textbox == 0)
                return;
            if (array[textbox].Text != "" && (!array[textbox].Text.EndsWith(";")) && (!array[textbox].Text.EndsWith("&")) && textbox != 7 && textbox != 13 && textbox != 14 && textbox != 17)
            array[textbox].Text = array[textbox].Text.ToString() + ";";

       
            
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (textbox == 0)
                return;
            if (array[textbox].Text != "" && (!array[textbox].Text.EndsWith(";")) && (!array[textbox].Text.EndsWith("&")) && textbox != 7 && textbox != 13 && textbox != 14 && textbox != 17)
            array[textbox].Text = array[textbox].Text.ToString() + "&";
        
        }

        private void textBox5_Enter(object sender, EventArgs e)
        {
            textbox = 5;
        }

        private void textBox7_Enter(object sender, EventArgs e)
        {
            textbox = 7;
        }

        private void textBox13_Enter(object sender, EventArgs e)
        {
            textbox = 13;
        }

        private void textBox14_Enter(object sender, EventArgs e)
        {
            textbox = 14;
        }

        private void textBox16_Enter(object sender, EventArgs e)
        {
            textbox = 16;
        }

        private void textBox15_Enter(object sender, EventArgs e)
        {
            textbox = 15;
        }

      /*  private void button8_Click(object sender, EventArgs e)
        {
            if (textbox == 0)
                return;
            if (array[textbox].Text == "" && textbox != 5 && textbox != 15 && textbox != 16)
                array[textbox].Text = array[textbox].Text.ToString() + "<";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (textbox == 0)
                return;
            if (array[textbox].Text == "" && textbox != 5 && textbox != 15 && textbox != 16)
                array[textbox].Text = array[textbox].Text.ToString() + "<";
        }*/

        private void textBox17_Enter(object sender, EventArgs e)
        {
            textbox = 17;
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button28_Click(object sender, EventArgs e)
        {/*
            if (!(comboBox9.SelectedIndex > -1 && comboBox9.SelectedIndex < comboBox9.Items.Count) && (textBox19.Text == "") && (textBox5.Text == "") && (textBox7.Text == "") && (textBox13.Text == "") && (textBox14.Text == "") && (!checkBox1.Checked) && (!checkBox2.Checked) && textBox16.Text == "" && textBox15.Text == "" && textBox17.Text == "" && !(comboBox7.SelectedIndex > -1 && comboBox7.SelectedIndex < comboBox7.Items.Count) && !((comboBox7.SelectedIndex > -1 && comboBox7.SelectedIndex < comboBox7.Items.Count)))
                return;

            int x = 0;
            String query = "select * from items where ";
            if (textBox19.Text != "")
            {
                textBox19.Text.Replace("&", "%' AND Serial_no like '%");
                query += " (Serial_no like  '%" + textBox19.Text.Replace(";", "%' OR Serial_no like '%") + "%' )AND ";
            }
            if (textBox5.Text != "")
            {
                textBox5.Text.Replace("&", "%' AND name like '%");
                query += " (name like  '%" + textBox5.Text.Replace(";", "%' OR name like '%") + "%' )AND ";
            }
        if (textBox7.Text != "")
        {
            if(radioButton1.Checked==true)
                query += "(acq_value = " + textBox7.Text + ") AND ";
            else if(radioButton2.Checked==true)
                query += "(acq_value > " + textBox7.Text + ") AND ";
            else if(radioButton3.Checked==true)
                query += "(acq_value < " + textBox7.Text + ") AND ";
        }
        if (textBox13.Text != "")
        {
            if (radioButton6.Checked == true)
                query += "(accum_value =  " + textBox13.Text + ") AND ";
            else if (radioButton5.Checked == true)
                query += "(accum_value >  " + textBox13.Text + ") AND ";
            else if (radioButton4.Checked == true)
                query += "(accum_value <  " + textBox13.Text + ") AND ";
        }
        if (textBox14.Text != "")
        {
            if (radioButton9.Checked == true)
                query += "(book_value = " + textBox14.Text + ") AND ";
            else if (radioButton8.Checked == true)
                query += "(book_value > " + textBox14.Text + ") AND ";
            else if (radioButton7.Checked == true)
                query += "(book_value < " + textBox14.Text + ") AND ";
           
        }
        if (checkBox1.Checked)
        {
            if (radioButton12.Checked == true)
                query += "(purchase_date = " + dateTimePicker3.Value.ToShortDateString() + ") AND ";
            else if (radioButton11.Checked == true)
                query += "(purchase_date > " + dateTimePicker3.Value.ToShortDateString() + ") AND ";
            else if (radioButton10.Checked == true)
                query += "(purchase_date < " + dateTimePicker3.Value.ToShortDateString() + ") AND ";
        }
        if (textBox16.Text != "")
        {
            textBox16.Text.Replace("&", "%' AND refresh_category = '%");
            query += "(refresh_category = '%" + textBox16.Text.Replace(";", "%' OR refresh_category = '%") + "%') AND ";
        }
        if (checkBox2.Checked)
        {
            if (radioButton15.Checked == true)
                query += "(refresh_date = " + dateTimePicker4.Value.ToShortDateString() + ") AND ";
            else if (radioButton14.Checked == true)
                query += "(refresh_date > " + dateTimePicker4.Value.ToShortDateString() + ") AND ";
            else if (radioButton13.Checked == true)
                query += "(refresh_date < " + dateTimePicker4.Value.ToShortDateString() + ") AND ";
           
        }
        if (comboBox5.SelectedIndex > -1 && comboBox5.SelectedIndex < comboBox5.Items.Count)
        {
            query += "(type_id in(select id from types where name  like '%" + comboBox5.Text + "%')) AND ";
        }
        if (comboBox9.SelectedIndex > -1 && comboBox9.SelectedIndex < comboBox9.Items.Count)
        {
            query += "(Location  like '%" + comboBox9.Text + "%') AND ";
        }
        if (textBox15.Text != "")
        {
            textBox15.Text.Replace("&", "%' OR name like '%");
            query += " (user_id in(select id from users where name like '%" + textBox15.Text.Replace(";", "%' OR name like '%") + "%')) AND ";
        }
        if (textBox17.Text != "")
        {
            if (radioButton18.Checked == true)
                query += "(id in(select item_id from details where value like '" + textBox17.Text + "')) AND ";
            else if (radioButton17.Checked == true)
                query += "(id in(select item_id from details where value >'" + textBox17.Text + "')) AND ";
            else if (radioButton16.Checked == true)
                query += "(id in(select item_id from details where value <'" + textBox17.Text + "')) AND ";
            
        }
        if (comboBox7.SelectedIndex > -1 && comboBox7.SelectedIndex < comboBox7.Items.Count)
        {
            query += "(id in (select item_id from details where detail_type_id in (select id from detail_types where name like '%"+comboBox7.Text+"%'))) AND ";
        }

        query = query.Substring(0, query.Length - 4);
            OdbcCommand get = new OdbcCommand(query, con);
            if (con.State != ConnectionState.Open)
                con.Open();
            
             OdbcDataReader reader = get.ExecuteReader();
             tb = new DataTable();
             tb.Columns.Add("ID");
             tb.Columns.Add("Name");
             tb.Columns.Add("serial");
             tb.Columns.Add("condition");
             tb.Columns.Add("tagging");
             tb.Columns.Add("Location");
             tb.Columns.Add("acq_value");
             tb.Columns.Add("accum_value");
             tb.Columns.Add("book_value");
             tb.Columns.Add("purchase_date");
             tb.Columns.Add("refresh_category");
             tb.Columns.Add("refresh_date");
             tb.Columns.Add("Type");
             tb.Columns.Add("User ID");
            
             while (reader.Read())
             {
                 tb.Rows.Add(new object[] { reader[0].ToString(), reader[1].ToString(), reader[11].ToString(), reader[12].ToString(), reader[13].ToString(), reader[14].ToString(), reader[3].ToString(), reader[4].ToString(), reader[5].ToString(), reader[6].ToString(), reader[7].ToString(), reader[8].ToString(), reader[9].ToString() });
             }
            
             dataGridView1.DataSource = tb;
             tabControl1.SelectedIndex = 5;
             dataGridView1.Columns[0].Visible = false;*/
        }

        private void button10_Click(object sender, EventArgs e)
        {
          
        }

        private void reportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            
           
        }

        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void searchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            search s = new search();
            s.Show();
        }

        private void searchToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            search s = new search();
            s.Show();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            if (((CocaCola_Inventory_System.Forms.Container)this.MdiParent).security < 2)
            {
                MessageBox.Show("Not Authorized");
                return;
            }
            if (textBox7.Text == "")
            {
                MessageBox.Show("Please Insert Name");
                return;
            }
            Insert i = new Insert(((CocaCola_Inventory_System.Forms.Container)this.MdiParent).con);
            if (i.condition(textBox7.Text, textBox5.Text, ((CocaCola_Inventory_System.Forms.Container)this.MdiParent).id))
            {
                MessageBox.Show("Condition Inserted Successfuly");
                textBox5.Text = "";
                textBox7.Text = "";
            }
            else
                MessageBox.Show("Condition Failed To Insert");
           
        }

        private void button7_Click_1(object sender, EventArgs e)
        {
           
           
            if (((CocaCola_Inventory_System.Forms.Container)this.MdiParent).security < 2)
            {
                MessageBox.Show("Not Authorized");
                return;
            }
            try
            {
                Convert.ToInt32(textBox15.Text);
            }
            catch
            {
                MessageBox.Show("Invalid Data");
                return;
            }
            if (textBox14.Text == "")
            {
                MessageBox.Show("Please Insert Name");
                return;
            }
            Insert i = new Insert(((CocaCola_Inventory_System.Forms.Container)this.MdiParent).con);
            if (i.category(textBox14.Text, Convert.ToInt32(textBox15.Text), textBox13.Text, ((CocaCola_Inventory_System.Forms.Container)this.MdiParent).id))
            {
                MessageBox.Show("Category Inserted Successfuly");

                textBox13.Text = "";
                textBox14.Text = "";
                textBox15.Text = "";
            }
            else
                MessageBox.Show("category Failed To Insert");

        }

        private void button8_Click(object sender, EventArgs e)
        {
           

            if (((CocaCola_Inventory_System.Forms.Container)this.MdiParent).security < 2)
            {
                MessageBox.Show("Not Authorized");
                return;
            }
            if (textBox19.Text == "")
            {
                MessageBox.Show("Please Insert Name");
                return;
            }
            try
            {
                Convert.ToInt32(textBox16.Text);

            }
            catch
            {
                MessageBox.Show("Invalid Data");
                return;
            }
            Insert i = new Insert(((CocaCola_Inventory_System.Forms.Container)this.MdiParent).con);
            if (i.depres(textBox19.Text, Convert.ToInt32(textBox16.Text), textBox17.Text, ((CocaCola_Inventory_System.Forms.Container)this.MdiParent).id))
            {
                MessageBox.Show("Depressiation Inserted Successfuly");
                textBox16.Text = "";
                textBox17.Text = "";
                textBox19.Text = "";
            }
            else
                MessageBox.Show("Depressiation Failed To Insert");
            

        }

        private void textBox20_TextChanged(object sender, EventArgs e)
        {
            
            if (textBox20.Text == "")
                user.DefaultView.RowFilter = "";
            string s = textBox20.Text;
            string query = "";
            string[] keys = s.Split(' ');
            foreach (string key in keys)
                if (key != "")
                    query += "name like '*" + key + "*' AND ";
            if (query.Length < 3)
                return;
            query = query.Substring(0, query.Length - 4);
            user.DefaultView.RowFilter = query;
        }

        private void label27_Click(object sender, EventArgs e)
        {

        }

        private void label29_Click(object sender, EventArgs e)
        {

        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox12_TextChanged(object sender, EventArgs e)
        {

        }

        private void label16_Click(object sender, EventArgs e)
        {

        }

        private void label17_Click(object sender, EventArgs e)
        {

        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
        {
            TabPage CurrentTab = tabControl1.TabPages[e.Index];
            Rectangle ItemRect = tabControl1.GetTabRect(e.Index);
            SolidBrush FillBrush = new SolidBrush(Color.Navy);
            SolidBrush TextBrush = new SolidBrush(Color.WhiteSmoke);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            //If we are currently painting the Selected TabItem we'll
            //change the brush colors and inflate the rectangle.
            if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
            {
                FillBrush.Color = Color.Gray;
                TextBrush.Color = Color.Maroon;
                ItemRect.Inflate(2, 2);
            }

            //Set up rotation for left and right aligned tabs
            if (tabControl1.Alignment == TabAlignment.Left || tabControl1.Alignment == TabAlignment.Right)
            {
                float RotateAngle = 90;
                if (tabControl1.Alignment == TabAlignment.Left)
                    RotateAngle = 270;
                PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
                e.Graphics.TranslateTransform(cp.X, cp.Y);
                e.Graphics.RotateTransform(RotateAngle);
                ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
            }

            //Next we'll paint the TabItem with our Fill Brush
            e.Graphics.FillRectangle(FillBrush, ItemRect);

            //Now draw the text.
            e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, RectangleF.Inflate(ItemRect, ItemRect.X, ItemRect.Y), sf);

            //Reset any Graphics rotation
            e.Graphics.ResetTransform();

            //Finally, we should Dispose of our brushes.
            FillBrush.Dispose();
            TextBrush.Dispose();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            retrieve r = new retrieve(((CocaCola_Inventory_System.Forms.Container)this.MdiParent).con);
            detail = r.getdetail_types();
            
            user = r.getusers();
            

            conditions = r.getCondtions();
           

            depressiation = r.getdepressiation();
            

            category = r.getcategory();
           
            type = r.gettypes();

            BU = r.getBU();
            Countries = r.getcountries();
            Locations = r.getlocations();

            //if (con.State != ConnectionState.Closed)
            // con.Close();
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

        {
            comboBox4.DataSource = detail;
            comboBox4.DisplayMember = "name";
            comboBox4.ValueMember = "id";

            comboBox2.DataSource = user;
            comboBox2.DisplayMember = "name";
            comboBox2.ValueMember = "id";
            comboBox5.DataSource = conditions;
            comboBox5.DisplayMember = "name";
            comboBox5.ValueMember = "id";
            comboBox7.DataSource = depressiation;
            comboBox7.DisplayMember = "name";
            comboBox7.ValueMember = "id";
            comboBox6.DataSource = category;
            comboBox6.DisplayMember = "name";
            comboBox6.ValueMember = "id";

            comboBox1.DataSource = type;
            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember = "id";


            comboBox8.DataSource = BU;
            comboBox9.DataSource = Countries;
            comboBox10.DataSource = Locations;

            comboBox8.DisplayMember = "name";
            comboBox8.ValueMember = "id";
            comboBox9.DisplayMember = "name";
            comboBox9.ValueMember = "id";
            comboBox8.DisplayMember = "name";
            comboBox8.ValueMember = "id";
            comboBox10.DisplayMember = "name";
            comboBox10.ValueMember = "id";

            Countries.DefaultView.RowFilter = "id = -1";
            Locations.DefaultView.RowFilter = "id = -1";
            comboBox8.SelectedIndex = -1;
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox8_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox8.SelectedIndex >= 0)
                Countries.DefaultView.RowFilter = "buid = " + BU.Rows[comboBox8.SelectedIndex][0].ToString();
            else
            {
                Countries.DefaultView.RowFilter = "id = -1";
                Locations.DefaultView.RowFilter = "id = -1";
            }
            comboBox9.SelectedIndex = -1;
            comboBox10.SelectedIndex = -1;
        }

        private void comboBox9_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox9.SelectedIndex >= 0)
                Locations.DefaultView.RowFilter = "countryid = " + Countries.Rows[comboBox9.SelectedIndex][0].ToString();
            else
                Locations.DefaultView.RowFilter = "id = -1";

            comboBox10.SelectedIndex = -1;
        }

        private void textBox20_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.ToString() == "\r" && comboBox2.SelectedIndex>-1)
            {
                dateTimePicker3.Focus();
            }
        }

        private void comboBox10_KeyPress(object sender, KeyPressEventArgs e)
        {
            
        }

        

       
       

        

       
        

       

          
        

        

        

       
        }
    }